home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / bin / fontconfig-voodoo < prev    next >
Encoding:
Text File  |  2007-03-30  |  2.7 KB  |  89 lines

  1. #!/usr/bin/python
  2.  
  3. import os
  4. import sys
  5. from optparse import OptionParser
  6.  
  7. from LanguageSelector import FontConfig
  8. from gettext import gettext as _
  9.  
  10.  
  11. def main():
  12.     
  13.     def abort(msg=None):
  14.         " helper for a clean abort "
  15.         if not options.silent:
  16.             if msg:
  17.                 print msg
  18.             print _("Aborting")
  19.         sys.exit(1)
  20.  
  21.     usage = "usage: %prog [options]"
  22.     # init the option parser
  23.     parser = OptionParser(usage)
  24.     parser.add_option("-f", "--force", dest="force",
  25.                       action="store_true",
  26.                       help=_("Force even when a configuration exists"))
  27.     parser.add_option("-s", "--set", dest="lang",
  28.                       help=_("Set fontconfig voodoo for the selected "
  29.                              "language"))
  30.     parser.add_option("-a", "--auto", dest="auto",
  31.                       action="store_true",
  32.                       help=_("Guess a configuration based on the "
  33.                              "LANGUAGE environment. Sets the config to "
  34.                              "'none' if nothing suitable was found"))
  35.     parser.add_option("-l", "--list", dest="list",
  36.                       action="store_true",
  37.                       help=_("List the available fontconfig-voodoo configs"))
  38.     parser.add_option("-c", "--current", dest="show_current",
  39.                       action="store_true",
  40.                       help=_("Show the current fontconfig-voodoo config"))
  41.     parser.add_option("-q", "--quiet",
  42.                       action="store_true", dest="silent", default=False)
  43.  
  44.     # check if we have arguments at all
  45.     if len(sys.argv[1:]) == 0:
  46.         parser.print_help()
  47.         sys.exit(0)
  48.  
  49.     # parse them
  50.     (options, args) = parser.parse_args()
  51.  
  52.     # do the work
  53.     fc = FontConfig.FontConfigHack()
  54.  
  55.     if options.show_current:
  56.         try:
  57.             if options.silent:
  58.                 print fc.getCurrentConfig()
  59.             else:
  60.                 print "Current config: %s" % fc.getCurrentConfig()
  61.         except FontConfig.ExceptionUnconfigured:
  62.             print _("Unconfigured")
  63.         sys.exit(0)
  64.  
  65.     if options.list:
  66.         print "\n".join(fc.getAvailableConfigs())
  67.         sys.exit(0)
  68.         
  69.     if os.path.exists(fc.configFile) and not options.force:
  70.         abort(_("A configuration exists already. Use '--force' to "
  71.                 "overwrite it. "))
  72.  
  73.     if options.auto:
  74.         try:
  75.             fc.setConfigBasedOnLocale()
  76.         except FontConfig.ExceptionNoConfigForLocale:
  77.             pass
  78.  
  79.     if options.lang:
  80.         try:
  81.             fc.setConfig(options.lang)
  82.         except FontConfig.ExceptionNoConfigForLocale:
  83.             abort(_("No fontconfig-voodoo configuration found for the "
  84.                     "selected locale"))
  85.     
  86.     
  87. if __name__ == "__main__":
  88.     main()
  89.